<?php

declare(strict_types=1);

/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

use function Hyperf\Support\env;
use function Hyperf\Support\value;

return [
    'enable' => [
        'discovery' => true,
        'register' => true,
    ],
    'consumers' => value(function () {
        // 获取公共配置
        $services = require BASE_PATH . '/../api-client/Config/consumer.php';

        $consumers = [];
        // 循环消费注册
        foreach ($services as $name => $config) {
            $consumers[] = [
                'name' => $name,
                'service' => $config['interface'],
                'protocol' => $config['protocol'] ?? 'jsonrpc',
                'load_balancer' => $config['load_balancer'] ?? 'weighted-round-robin',
                'registry' => $config['registry'],
                'options' => $config['options'],
            ];
        }

        return $consumers;
    }),
    'providers' => [],
    'drivers' => [
        'consul' => [
            'uri' => 'http://127.0.0.1:8500',
            'token' => '',
            'check' => [
                'deregister_critical_service_after' => '90m',
                'interval' => '1s',
            ],
        ],
        'nacos' => [
            // nacos server url like https://nacos.hyperf.io, Priority is higher than host:port
            // 'url' => '',
            // The nacos host info
            'host' => env('NACOS_HOST', '127.0.0.1'),
            'port' => env('NACOS_PORT', '8848'),
            // The nacos account info
            'username' => env('NACOS_USERNAME', 'nacos'),
            'password' => env('NACOS_PASSWORD', 'nacos'),
            'guzzle' => [
                'config' => null,
            ],
            'group_name' => env('APP_ENV', 'prod'),
            'namespace_id' => env('NACOS_NAMESPACE_ID', 'public'),
            'heartbeat' => 5,
            'ephemeral' => true,
            'cluster' => 'DEFAULT',
            // Only support for nacos v2.
            // grpc目前用不了不知道什么情况
            'grpc' => [
                'enable' => false,
                'heartbeat' => 1,
            ],
        ],
    ],
];
